package m202406.d28;

import java.util.Arrays;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/6/28 22:53
 */
public class Q179 {

    public static void main(String[] args) {
        Q179 q179 = new Q179();
        q179.largestNumber(new int[]{3,30});
    }

    public String largestNumber(int[] nums) {
        String[] str = Arrays.stream(nums)
                .mapToObj(String::valueOf)
                .toArray(String[]::new);

        Arrays.sort(str, (s1, s2) -> {
            int p = 0;
            for (; p < s1.length() && p < s2.length(); p++) {
                char c1 = s1.charAt(p);
                char c2 = s2.charAt(p);
                if (c1 == c2) {
                    continue;
                }
                return c2 - c1;
            }
            if (s1.length() == s2.length()) {
                return 0;
            }
            if (p == s1.length()) {
                return s2.charAt(p) - s2.charAt(p - 1);
            } else {
                return s1.charAt(p-1) - s1.charAt(p );
            }
        });

        return String.join("", str);
    }
}
